package com.bite.forum.controller;

import com.bite.forum.common.AppResult;
import com.bite.forum.exception.ApplicationException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@SecurityRequirement(name = "BearerAuth")
@Tag(name = "测试类信息",description = "测试类信息接口")
@RequestMapping("/test")
public class TestController {
    @Operation(summary = "测试hello Spring-Boot!")
    @GetMapping("/hello")
    public String hello(){
        return "hello Spring-Boot!";
    }

    @Operation(summary = "测试传入的姓名信息")
    @GetMapping("/hello2")
    public String hello2(
            @Schema(description = "传入的姓名信息")
            @RequestParam String name
    ) {
        return "hello： " + name;
    }

    @Operation(summary = "测试exception,显示抛出的异常信息")
    @GetMapping("/exception")
    public AppResult testException () throws Exception {
        throw new Exception("测试Exception异常");
    }

    @Operation(summary = "测试handleExceptionHandler,显示抛出的自定义异常信息")
    @GetMapping("/handleExceptionHandler")
    public AppResult testHandleExceptionHandler () {
        throw new ApplicationException("测试ApplicationException异常");
    }
}
